package ParallelMachineArrangeImpl;

import java.util.ArrayList;
import java.util.List;

// 3.1.2可中断时间表长度问题
public class _3_1_2_TTLp extends ParallelMachineArrange {
    @Override
    public void solve() {
        artifacts = new ArrayList<>();
        if(process==null){
            process = new int[]{2,1,4,1};
        }
        int max_pj = Integer.MIN_VALUE;
        for (int p : process) {
            Artifact a = new Artifact();
            a.process = p;a.remain_process = p;
            artifacts.add(a);
            max_pj = Math.max(max_pj,p);
        }
        int max_ct = getCompleteTime(artifacts)/machines;
        int max_t = Math.max(max_ct,max_pj);
        System.out.println("排序方式：");
        int t = 0;
        for (Artifact artifact : artifacts) {
            if( (t += artifact.process) <= max_t){
                System.out.print(artifact);
                System.out.print(" -> ");
            }else {
                System.out.print(artifact);
                System.out.printf("(加工%d分钟)\n", artifact.process - t + max_t);
                System.out.print(artifact);
                System.out.printf("(加工%d分钟) -> ",t - max_t);
                t = 0;
            }
        }

        System.out.println("\n用时不大于：" + Math.max(max_pj,max_ct));
    }
}
